package com.hmall.common.config;

import com.hmall.common.interceptor.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 可以不设置拦截路径，因为在默认就是拦截所有路径
        // 而且此拦截器的作用是将请求头中的user-info放入UserContext中，而不是认证
        registry.addInterceptor(new UserInfoInterceptor())
                // 去除登录拦截
                .excludePathPatterns("/users/login");
//                .addPathPatterns("/**");
    }
}
